#include "primary_include_file.h"
#include "mb/op_wchar.h"

/* SQL/ASCII */
/* _line_40 */
static int op_ascii2wchar_with_len(const unsigned char *from, op_wchar *to, int len)
{
  int cnt = 0;
  while(len > 0 && *from) {
    *to++ = *from++;
    len--;
    cnt++;
  }
  *to = 0;
  return cnt;
}

/* _line_55 */
static int op_ascii_mblen(const unsigned char *s)
{
  return 1;
}

/* _line_61 */
static int op_ascii_dsplen(const unsigned char *s) 
{
  if (*s == '\0')
    return 0;
  if (*s < 0x20 || *s == 0x7f)
    return -1;

  return 1;
}

/* _line_951 */
static int op_ascii_verifier(const unsigned char *s, int len)
{
  return 1;
}

/* GBK */
/* _line_848 */
static int op_gbk_mblen(const unsigned char *s)
{
  int len;
  if (IS_HIGHBIT_SET(*s))
    len = 2;  /* kanji? */
  else 
    len = 1;  /* should be ascii */
  return len;
}

/* _line_860 */
static int op_gbk_dsplen(const unsigned char *s)
{
  int len;
  if (IS_HIGHBIT_SET(*s))
    len = 2;  /* kanji */
  else 
    len = op_ascii_dsplen(s); /* should be ASCII */

  return len;
}

/* _line_1190 */
static int op_gbk_verifier(const unsigned char *s, int len)
{
  int l, mbl;
  l = mbl = op_gbk_mblen(s);

  if (len < 1)
    return -1;

  while(--l > 0) {
    if (*++s == '\0')
      return -1;
  }

  return mbl;
}

/* encoding info table */
op_wchar_tbl op_wchar_table[] = {
  {op_ascii2wchar_with_len, op_ascii_mblen, op_ascii_dsplen, op_ascii_verifier, 1},  /* OP_SQL_ASCII */
  {0, op_gbk_mblen, op_gbk_dsplen, op_gbk_verifier, 2} /* OP_GBK */
}; 


